/*
 *******************************************************************************
 *
 * Copyright (C) 2019-2020 Dialog Semiconductor.
 * This computer program includes Confidential, Proprietary Information
 * of Dialog Semiconductor. All Rights Reserved.
 *
 *******************************************************************************
 */

package com.dialog.suotalib.interfaces.callbacks;

import android.bluetooth.BluetoothGattCharacteristic;

import com.dialog.suotalib.global.SuotaProfile;

public interface ISuotaManagerCallback {

    /**
     * Gets triggered every time the connection state changes.
     *
     * @param newStatus the new connection status
     */
    void onConnectionStateChange(SuotaProfile.SuotaManagerStatus newStatus);

    /**
     * Gets triggered when services get discovered.
     */
    void onServicesDiscovered();

    /**
     * Gets triggered when a characteristic is read.
     *
     * @param characteristicGroup the characteristic group that the library considers the current characteristic as part of
     * @param characteristic      the characteristic itself
     */
    void onCharacteristicRead(SuotaProfile.CharacteristicGroup characteristicGroup, BluetoothGattCharacteristic characteristic);

    /**
     * Gets triggered when all device info has been read.
     *
     * @param status indicates if there is actually info read (SUCCESS),
     *               or there was no available device info to read at all (NO_DEVICE_INFO)
     */
    void onDeviceInfoReadCompleted(SuotaProfile.DeviceInfoReadStatus status);

    /**
     * Gets triggered when all available suota info
     * (and device info if {@link com.dialog.suotalib.global.SuotaLibConfig#AUTO_READ_DEVICE_INFO Autoread Device Info Flag}
     * is set to <b>true</b>) has been read.
     */
    void onDeviceReady();

    /**
     * Gets triggered only if {@link com.dialog.suotalib.global.SuotaLibConfig#NOTIFY_SUOTA_LOG Suota Log Enabled Flag}
     * is set to <b>true</b>.
     *
     * @param state current suota protocol state
     * @param type type of log message
     * @param log log message
     */
    void onSuotaLog(SuotaProfile.SuotaProtocolState state, SuotaLogType type, String log);

    enum SuotaLogType {
        INFO,
        BLOCK,
        CHUNK
    }

    /**
     * Gets triggered only if {@link com.dialog.suotalib.global.SuotaLibConfig#NOTIFY_CHUNK_SEND Chunk Notification Flag}
     * is set to <b>true</b>.
     *
     * @param chunkCount chunk count of total chunks
     * @param totalChunks total chunks
     * @param chunk chunk count of current block
     * @param block block count
     * @param blockChunks total chunks in current block
     * @param totalBlocks total blocks
     */
    void onChunkSend(int chunkCount, int totalChunks, int chunk, int block, int blockChunks, int totalBlocks);

    void onBlockSent(int block, int totalBlocks);

    void updateSpeedStatistics(double current, double max, double min, double avg);

    void updateCurrentSpeed(double currentSpeed);

    /**
     * Gets triggered only if {@link com.dialog.suotalib.global.SuotaLibConfig#NOTIFY_UPLOAD_PROGRESS Upload Progress Flag}
     * is set to <b>true</b>.
     *
     * @param percent the percent of the firmware file already sent to device
     */
    void onUploadProgress(float percent);

    /**
     * Gets triggered only after Suota has finished successfully.
     *
     * @param totalElapsedSeconds       total elapsed time during suota protocol execution,
     *                                  equals to -1 in case the elapsed time cannot be calculated
     *                                  due to unexpected inner error. Should probably never occur.
     * @param imageUploadElapsedSeconds elapsed time during image upload
     *                                  equals to -1 in case the elapsed time cannot be calculated
     *                                  due to unexpected inner error. Should probably never occur.
     */
    void onSuccess(double totalElapsedSeconds, double imageUploadElapsedSeconds);

    /**
     * Gets triggered in case any unexpected event occurs.
     * In such cases you should probably disconnect,
     * destroy SuotaManager and retry from the beginning.
     *
     * @param errorCode one of the error codes found on SuotaProfile.Errors
     */
    void onFailure(int errorCode);

    /**
     * Gets triggered only if {@link com.dialog.suotalib.global.SuotaLibConfig#ALLOW_DIALOG_DISPLAY Allow Dialog Display Flag}
     * is set to true and the user decides to send reboot.
     */
    void onRebootSent();


    void  complete();
    void  onPythonData(Integer data) ;

}
